package demo01;
//连续和为0
import java.util.HashMap;
import java.util.Map;

class Solution {
    public int findMaxLength(int[] nums) {
        int L = nums.length;
        int sum = 0;
        int max = 0;
        Map<Integer,Integer> hash = new HashMap<Integer,Integer>();
        hash.put(0,-1);
        for(int i = 0; i < L;i++){
            sum = sum + (nums[i]==1?-1:1);//前缀和包括下标本身
            if(hash.containsKey(sum))
                max = Math.max(max,(i-hash.get(sum)));
        }
        return max;
    }}
